#include <iostream>
#include <vector>

using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right)
        : val(x), left(left), right(right) {}
};

vector<int> dfs(TreeNode* root, int fa, int depth, int x){
    if(root == nullptr) return vector<int> {-1,-1};
    if(root->val == x) return vector<int> {fa, depth};
    vector<int> left = dfs(root->left, root->val, depth+1, x);
    if(left[0] != -1){
        return left;
    }
    return dfs(root->right, root->val, depth+1, x);
}

bool isCousins(TreeNode* root, int x, int y) {
    vector<int> xf = dfs(root, 0, 0, x);
    vector<int> yf = dfs(root, 0, 0, y);
    return (xf[0] != yf[0]) && (xf[1] == yf[1]);
}

int main(){
    TreeNode* p = new TreeNode();
}